package cn.cubix.flow.controller.exception;

import cn.cubix.flow.util.Result;
import org.flowable.common.engine.impl.javax.el.PropertyNotFoundException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

@RestControllerAdvice
public class FlowableExceptionHandler {

    @ExceptionHandler(PropertyNotFoundException.class)
    public Object handlerMaxUploadFile(PropertyNotFoundException e){
        Pattern p = Pattern.compile("'(.*?)'");
        Matcher m = p.matcher(e.getMessage());
        String property = m.find()?m.group():"";
        property = property.isEmpty()?property:("["+property.substring(1,property.length()-1)+"]");
        return Result.FAILURE("缺少参数"+property);
    }

}
